;!function (win) {
    "use strict";

    var baseCRUD = {};
    var baseUtil = {};

    baseCRUD.GETRequest = function (opertion) {
        $.ajax({
            async: opertion.async,
            url: opertion.url,
            type: "GET",
            success: function (res) {
                if (res.code == 200) {
                    opertion.success(res.data)
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    };

    baseCRUD.PUTRequest = function (opertion) {
        $.ajax({
            url: opertion.url,
            type: "PUT",
            contentType: "application/json",
            data: JSON.stringify(opertion.data),
            success: function (res) {
                if (res.code == 200) {
                    opertion.success(res)
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }

    baseCRUD.DELRequest = function (opertion) {
        $.ajax({
            url: opertion.url,
            type: "DELETE",
            contentType: "application/json",
            success: function (res) {
                if (res.code == 200) {
                    opertion.success(res)
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }

    baseCRUD.request = function (opertion) {
        $.ajax({
            url: opertion.url,
            type: opertion.type,
            contentType: "application/json",
            data: JSON.stringify(opertion.data),
            success: function (res) {
                if (res.code == 200) {
                    opertion.success(res)
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }

    baseCRUD.POSTRequest = function (opertion) {
        $.ajax({
            url: opertion.url,
            type: "POST",
            contentType: "application/json",
            data: JSON.stringify(opertion.data),
            success: function (res) {
                if (res.code == 200) {
                    opertion.success(res)
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }

    baseUtil.msgOkDoing = function (msg, callback) {
        layer.msg(msg, {
            icon: 1,
            time: 1000
        }, callback);
    }


    /**
     * 时间戳转换字符串
     * @param time
     */
    baseUtil.dateString = function (time) {
        return util.toDateString(time);
    }
    win.baseUtil = baseUtil;
    win.basecrud = baseCRUD;

}(window);



